package com.vf.activity.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vf.activity.domain.DTO.ActivitiesDTO;
import com.vf.activity.domain.VO.ActivityVO;
import com.vf.activity.domain.VO.AddActivityVO;
import com.vf.common.annotation.Anonymous;
import com.vf.user.domain.VO.GroupTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vf.common.annotation.Log;
import com.vf.common.core.controller.BaseController;
import com.vf.common.core.domain.AjaxResult;
import com.vf.common.enums.BusinessType;
import com.vf.activity.domain.Activities;
import com.vf.activity.service.IActivitiesService;
import com.vf.common.utils.poi.ExcelUtil;
import com.vf.common.core.page.TableDataInfo;

/**
 * 活动Controller
 * 
 * @author LBS
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/activity/activities")
@Api(tags="活动")
public class ActivitiesController extends BaseController
{
    @Autowired
    private IActivitiesService activitiesService;

    /**
     * 查询活动列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:list')")
    @GetMapping("/list")
    public TableDataInfo list(Activities activities)
    {
        startPage();
        List<Activities> list = activitiesService.selectActivitiesList(activities);
        return getDataTable(list);
    }

    /**
     * 导出活动列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:export')")
    @Log(title = "活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Activities activities)
    {
        List<Activities> list = activitiesService.selectActivitiesList(activities);
        ExcelUtil<Activities> util = new ExcelUtil<Activities>(Activities.class);
        util.exportExcel(response, list, "活动数据");
    }

    /**
     * 获取活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(activitiesService.selectActivitiesByActivityId(activityId));
    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:add')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Activities activities)
    {
        return toAjax(activitiesService.insertActivities(activities));
    }

    /**
     * 修改活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:edit')")
    @Log(title = "活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Activities activities)
    {
        return toAjax(activitiesService.updateActivities(activities));
    }

    /**
     * 删除活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activities:remove')")
    @Log(title = "活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(activitiesService.deleteActivitiesByActivityIds(activityIds));
    }

    /**
     * 通过活动名称查询活动信息
     */
    @GetMapping("/getActivityByName/{activityName}")
    @Anonymous
    @ApiOperation("通过活动名称查询活动信息")
    public TableDataInfo getActivityByName(@PathVariable String activityName)
    {
        List<ActivitiesDTO> activitiesList = activitiesService.selectActivitiesListByName(activityName);
        return getDataTable(activitiesList);
    }


    /**
     * 查询活动列表
     */
    @GetMapping("/listAll")
    @Anonymous
    @ApiOperation(value = "查询所有活动列表")
    public TableDataInfo listAll(Activities activities)
    {
        startPage();
        List<ActivitiesDTO> list = activitiesService.selectActivitiesAllList(activities);
        return getDataTable(list);
    }

    /**
     * 通过分组查看查询活动列表
     */
    @GetMapping("/listByGroup")
    @Anonymous
    @ApiOperation(value = "通过分组查看查询活动列表")
    public TableDataInfo listByGroup(@RequestBody Long[] userIds){
        startPage();
        List<ActivitiesDTO> list = activitiesService.listByGroup(userIds);
        return getDataTable(list);
    }

    // 发布活动
    @PostMapping("/addActivity")
    @Anonymous
    @ApiOperation(value = "发布活动")
    public AjaxResult addActivity(@RequestBody ActivityVO activityVO){
        // 调用服务层方法添加活动，并转换结果为AjaxResult对象返回
        return toAjax(activitiesService.addActivity(activityVO));
    }

    // 加入活动
    @PostMapping("/joinActivity")
    @Anonymous
    @ApiOperation(value = "加入活动")
    public AjaxResult joinActivity(@RequestBody AddActivityVO addActivityVO){
        // 调用服务层方法加入活动，并转换结果为AjaxResult对象返回
        return toAjax(activitiesService.joinActivity(addActivityVO));
    }

}
